package com.aeoj.clientmanagement.controller;

/**
 * PkController
 * author: ZSM
 * time: 2025-04-23 12:45
 */

import cn.hutool.jwt.JWTUtil;
import com.aeoj.clientmanagement.domain.pk.BattleRecord;
import com.aeoj.clientmanagement.domain.pk.dto.BattleRecordDTO;
import com.aeoj.clientmanagement.domain.response.R;
import com.aeoj.clientmanagement.domain.user.vo.SysUserVO;
import com.aeoj.clientmanagement.domain.userscore.UserScore;
import com.aeoj.clientmanagement.enums.ResponseCodeEnum;
import com.aeoj.clientmanagement.enums.pk.BattleResultEnum;
import com.aeoj.clientmanagement.service.BattleRecordService;
import com.aeoj.clientmanagement.service.UserScoreService;
import com.aeoj.clientmanagement.utils.user.UserUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/client/pk")
public class PkController {
    @Resource
    private BattleRecordService battleRecordService;
    @Resource
    private UserScoreService userScoreService;

    /**
     * 获取匹配token
     * @param request
     * @return
     */
    @PostMapping("match")
    public R match(HttpServletRequest request) {
        SysUserVO loginUser = UserUtils.getLoginUser(request);

        Map<String, Object> map = new HashMap<>();
        map.put("userId", loginUser.getUserId());
        map.put("expire_time", System.currentTimeMillis() + 1000 * 60 * 60);

        String token = JWTUtil.createToken(map, loginUser.getUserId().toString().getBytes());
        return R.ok(token);
    }
}
